<%--
  Created by IntelliJ IDEA.
  User: User
  Date: 2020/6/1
  Time: 20:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>登录结果</title>
</head>
<jsp:useBean id="db" class='hello.DB'></jsp:useBean>
<body style="background:url(page/1.jpg)">
<%@ page import="java.sql.*" %>
<%
		db.init();
		String sql="select * from users where'"+request.getParameter("user")+"'=username and '"+request.getParameter("pwd")+"'=password";
		ResultSet rs=db.executeQuery(sql);
		if(rs.next()){
			session.setAttribute("user",request.getParameter("user"));//保存用户名到session
	%><!-- 成功 -->

<h1 align="center">欢迎您！</h1>
<div align="center"><form action="ticket.jsp" >
    <input checked="true" name="gender"type="radio" value="今天"/>今天
    <input name="gender"type="radio" value="明天"/>明天
    <input name="gender"type="radio" value="后天"/>后天<br>
    出发站：<input type="text" name='begin' value="福州"/><br>
    终点站：<input type="text" name='end' value="莆田"/><br>
    <input type="submit" value='查询车票'/>
</form></div>



<br><br>
<h2 >我的订单</h2><!-- 显示我的所有订单 -->
<%
    sql="select * from orders where username='"+request.getParameter("user")+"'";
    rs=db.executeQuery(sql);
%><div ><table border="1">
    <tr><td>订单号</td><td>列车号</td><td>出发-终点</td><td>座位类型</td><td>乘客</td>
        <td>出发日期</td><td>购买时间</td><td>操作</td>
            <%
			while(rs.next()){
				if(rs.getString("status").equals("已退票")){
					%>
    <tr>
        <td><%out.print(rs.getString("ordernum")); %></td>
        <td><%out.print(rs.getString("trainnum")); %></td>
        <td><%out.print(rs.getString("Originating")+"-"+rs.getString("arriving")); %></td>
        <td><%out.print(rs.getString("seattype")); %></td>
        <td><%out.print(rs.getString("passenger")); %></td>
        <td><%out.print(rs.getString("time")); %></td>
        <td><%out.print(rs.getString("pur_time")); %></td>
        <td>已退</td>
    </tr>
    <%
    }
    else {
    %>
    <tr>
        <td><%out.print(rs.getString("ordernum")); %></td>
        <td><%out.print(rs.getString("trainnum")); %></td>
        <td><%out.print(rs.getString("Originating")+"-"+rs.getString("arriving")); %></td>
        <td><%out.print(rs.getString("seattype")); %></td>
        <td><%out.print(rs.getString("passenger")); %></td>
        <td><%out.print(rs.getString("time")); %></td>
        <td><%out.print(rs.getString("pur_time")); %></td>
        <td><a  href="我的订单.jsp?ordernum=<%=rs.getString("ordernum")%>">退票</a></td>
    </tr>
    <%
            }

        }
    %></table></div><%
		}
		else{
	%><!-- 失败 -->
<h1 align="center">用户名密码不匹配</h1>

<%}
    db.close();
%>
</body>
</html>
